/**
 * create by young (young2f@outlook.com) on 2020/12/4
 * 采购物料记录
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    salesOrderCode: { type: String, _type: 'string', title: '订单编码', enableArea: ['detail',  'table',  'search'], },
    division: { type: String, _type: 'string', title: '事业部', enableArea: ['detail',  'table',  'search'], },
    customer: { type: String, _type: 'string', title: '客户', enableArea: ['detail',  'table',  'search'], },
    spLotId: { type: String, _type: 'string', title: '销售商品批次编码', required: true },
    prodCode: { type: String, _type: 'string', title: '编码', required: true ,enableArea: ['detail',  'table',  'search'],},
    prodName: {  type: 'string', inputType: 'string', title: '品名', enableArea: [ 'table', 'input', 'detail', ],  },
    count: { type: Number, _type: 'number', title: '数量', enableArea: ['detail',  'table',  'search'], },
    price: { type: Number, _type: 'number', title: '单价', enableArea: [ 'detail', 'table',  'search'], },
    pkgFee: { type: Number, _type: 'number', title: '包装费用', enableArea: ['detail',    'search'], },
    laborFee: { type: Number, _type: 'number', title: '劳务费用', enableArea: [ 'detail',  'search'], },
    taxDeductionPointForLaborCosts: { type: Number, _type: 'number', title: '单价', enableArea: [ 'detail',  'search'], },
    needInvoice: {  type: 'string', inputType: 'string', title: '编号', enableArea: [ 'input', 'detail', ],  },
    deliverWay: {  type: 'string', inputType: 'string', title: '发货方式', enableArea: [ 'table', 'input', 'detail', ],  },
    pkg: {  type: 'string', inputType: 'string', title: '包装', enableArea: [ 'table', 'input', 'detail', ],  },
    plannedShippingDate: { type: String, _type: 'string', title: '要求到货时间', enableArea: [ 'input', 'detail', 'search' ] },
    label: {  type: 'string', inputType: 'string', title: '标签', enableArea: [ 'table', 'input', 'detail', ],  },
    invoicingDate: {  type: 'date', inputType: 'date', title: '开票时间', enableArea: [ 'input',  ],  },
    invoicingCount: { type: Number, _type: 'number', title: '开票数量', enableArea: [  'detail', ],default:0},
    materials: {  type: 'array', inputType: 'array', title: '原料列表', enableArea: [ 'input',  ],  },
    materialLots: {  type: 'array', inputType: 'array', title: '原料批次列表', enableArea: [ 'input',  ],  },
    pkgMaterials: {  type: 'array', inputType: 'array', title: '包材列表', enableArea: [ 'input',  ],  },
    pkgLots: {  type: 'array', inputType: 'array', title: '包材批次列表', enableArea: [ 'input',  ],  },
    fileList: { type: Array, _type: 'array', title: '附件', enableArea: [  'search'] },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('SalesProdRecord', _schema);
};
